/*
 * main.c
 *
 *  Created on: Jan 29, 2013
 *      Author: justin
 */

#include "project_header.h"
#define debug 0

typedef enum fsm_mode_names {
	init = 0, run = 1, stop = 2, restart = 3, quit = 4, display = 5
} machine_state;    //enumerate declarations to simplify code readability of FSM state
const char display_msg[] = "Messaging mode";

int main() {
	unsigned long stoptimer_val = 0, runtimer_val = 0;
	int fsm_mode = init;
	while (1) {
		switch (fsm_mode) {
			case init:
				init_ticker(1000);    //start hardware timer with 1000usec resolution
				init_io();
				init_uart(0);
				fsm_mode = run;
				while (display_msg[i++]!=0)  ;
				break;
				/**----------------------------*/
			case (run):
				if (tick_ms >= runtimer_val + 500) {
					PORTA ^= PORTA;    //toggle LED
					runtimer_val = tick_ms;
				}
//			parse serial(serial_read(0));
//			if (serial_buffer_in)
				break;
				/**----------------------------*/
			case display:
//				sprintf(*display_msg,4);

				break;
			case stop:
				PORTA = 0x00;
				stoptimer_val = tick_ms;
				if (tick_ms >= runtimer_val + 500) {
					if (stoptimer_val) {

					}

				}
				break;
			case quit:
				//puts("MCU halting")
				while (1)
					;    //spin lock to hold system state
				break;
				/**----------------------------*/
			case restart:
//				sprintf("MCU is restarting");
				fsm_mode = init;
				break;
			default:
				break;
		}
	}
}
